/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.service.services.views.orgchart;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;


/**
 * Panel representing space between cells in "condensed" representation.
 *
 */
public class XJPanel1 extends JPanel
{
    /** Panel size. */
    private int size;

    /**
     * Creates a new XJPanel1 object.
     *
     * @param asize  Size of panel.
     */
    public XJPanel1(final int asize)
    {
        this.size = asize;
    }

    /**
     * Gets minimum size of the component.
     *
     * @return The minimum size according to panel size and orgchart mode.
     */
    @Override
	public final Dimension getMinimumSize()
    {
        if (OrgChartPanel.getDirection() == OrgChartPanel.HORIZONTAL)
        {
            return new Dimension(size, 0);
        }
        else
        {
            return new Dimension(0, size);
        }
    }

    /**
     * Gets preferred size of the component.
     *
     * @return The preferred size according to panel size and orgchart mode.
     */
    @Override
	public final Dimension getPreferredSize()
    {
        if (OrgChartPanel.getDirection() == OrgChartPanel.HORIZONTAL)
        {
            return new Dimension(size, 0);
        }
        else
        {
            return new Dimension(0, size);
        }
    }

    /**
     * Gets maximum size of the component.
     *
     * @return The maximum size according to panel size and orgchart mode.
     */
    @Override
	public final Dimension getMaximumSize()
    {
        if (OrgChartPanel.getDirection() == OrgChartPanel.HORIZONTAL)
        {
            return new Dimension(size, Integer.MAX_VALUE);
        }
        else
        {
            return new Dimension(Integer.MAX_VALUE, size);
        }
    }

    /**
     * Draws the component.
     *
     * @param g  Graphics on which to draw.
     */
    @Override
	public final void paint(final Graphics g)
    {
        super.paint(g);

        if (OrgChartPanel.getDirection() == OrgChartPanel.HORIZONTAL)
        {
            g.drawLine(0, 0, getWidth(), 0);
            g.drawLine(0, 1, getWidth(), 1);
        }
        else
        {
            g.drawLine(0, 0, 0, getHeight());
            g.drawLine(1, 0, 1, getHeight());
        }
    }
}
